package io.qar.mq.controller;

import io.qar.commons.tools.utils.Result;
import io.qar.mq.entity.SysUserEntity;
import io.qar.mq.producer.DemoProducerService;
import io.qar.mq.producer.RenProducerService;
import io.qar.mq.service.SysUserService;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

//@AllArgsConstructor
@RestController
@RequestMapping("rocketmq")
public class RocketMQController {
    @Autowired
    private RenProducerService renProducerService;

    @Autowired
    private DemoProducerService demoProducerService;

    @Autowired
    private SysUserService sysUserService;

    @GetMapping("list")
    public Result<List<SysUserEntity>> list(){
        List<SysUserEntity> list = sysUserService.getList();
        return new Result().ok(list);
    }

    @GetMapping("demo")
    public String demo(){
//        demoProducerService.producersMessage();
//        demoProducerService.sendOneWay();
//        demoProducerService.syncSend();
//        demoProducerService.asyncSend();
        demoProducerService.syncSendOrderly();
        return "demo";
    }

    @GetMapping("order")
    public String order() {
        renProducerService.sendOrder("订单001");

        return "success";
    }

    @GetMapping("pay")
    public String pay() {
        renProducerService.sendPay("支付001");

        return "success";
    }
}
